package view;

import entity.StudentDO;
import handler.AddStudentViewHandler;

import javax.swing.*;
import java.awt.*;

public class AddStudentView extends JDialog {
    JPanel jPanel = new JPanel();
    //    JLabel snoLabel = new JLabel("学号");
//    JTextField snoTxt = new JTextField();
    JLabel nameLabel = new JLabel("姓名");
    JTextField nameTxt = new JTextField();

    JLabel snoLabel = new JLabel("学号");
    JTextField snoTxt = new JTextField();

    JLabel sexLabel = new JLabel("性别");
    JTextField sexTxt = new JTextField();

    JLabel ageLabel = new JLabel("年龄");
    JTextField ageTxt = new JTextField();


    JLabel deptLabel = new JLabel("系别");
    JTextField deptTxt = new JTextField();


    JLabel speLabel = new JLabel("专业");
    JTextField speTxt = new JTextField();


    JLabel sclass = new JLabel("班级");
    JTextField classTxt = new JTextField();

    JButton addBtn = new JButton("添加");

    AddStudentViewHandler addStudentViewHandler;

    public AddStudentView(MainView mainView) {
        super(mainView, "添加信息", true);

        addStudentViewHandler = new AddStudentViewHandler(this, mainView);

        snoLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(snoLabel);
        snoTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(snoTxt);

        nameLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(nameLabel);
        nameTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(nameTxt);


        sexLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(sexLabel);
        sexTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(sexTxt);

        ageLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(ageLabel);
        ageTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(ageTxt);

        deptLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(deptLabel);
        deptTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(deptTxt);

        speLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(speLabel);
        speTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(speTxt);

        sclass.setPreferredSize(new Dimension(80, 30));
        jPanel.add(sclass);
        classTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(classTxt);


        addBtn.addActionListener(addStudentViewHandler);

        jPanel.add(addBtn);

        Container contenPane = getContentPane();
        contenPane.add(jPanel);

        setSize(600, 400);//大小
        setVisible(true);//可以看见
        setResizable(false);//不可变大小
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);//退出自动关闭
        setLocationRelativeTo(null);//居中
    }

    public StudentDO buildStudentDO() {
        StudentDO studentDO = new StudentDO();
        studentDO.setSno(Integer.valueOf(snoTxt.getText()));
        studentDO.setSname(nameTxt.getText());
        studentDO.setSex(sexTxt.getText());
        studentDO.setAge(ageTxt.getText());
        studentDO.setDept(deptTxt.getText());
        studentDO.setSpe(speTxt.getText());
        studentDO.setSclass(classTxt.getText());

        return studentDO;
    }

}
